package com.euq.controller;

import com.euq.entity.Cfg;
import com.euq.log.BusinessLog;
import com.euq.service.CfgService;
import com.euq.utils.SecurityUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cfg")
public class CfgController {
    @Autowired
    private CfgService cfgService;
    public static final Logger log = LoggerFactory.getLogger(CfgController.class);
    @GetMapping("/list")
    public PageInfo<Cfg> listCfg(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return cfgService.listCfg(page, size);
    }
    @PostMapping("/delete")
    @BusinessLog(logName = "参数删除",logType = "业务日志")
    public void deleteCfg(Long id) {
        log.info("用户{}删除参数", SecurityUtils.getCurrentUser().getUsername());
        cfgService.deleteCfg(id);
    }
    @PostMapping("/insert")
    @BusinessLog(logName = "新增参数",logType = "业务日志")
    public void insertCfg(String cfgName, String cfgValue,String cfgDescription) {
        log.info("用户{}新增参数{}", SecurityUtils.getCurrentUser().getUsername(), cfgName);
        cfgService.insertCfg(cfgName,cfgValue,cfgDescription);
    }
    @PostMapping("/select")
    public PageInfo<Cfg> selectCfg(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "5") int size ,@RequestParam String cfgName,@RequestParam String cfgValue) {
        return cfgService.selectCfg(page,size,cfgName,cfgValue);
    }
}
